<?php
/**
 * Created by PhpStorm.
 * User: admin
 * Date: 2016/9/14
 * Time: 14:41
 * 结账步骤二
 */
require('env.php');
require('init.inc.php');
include_once 'functions.php';
$db_oid = $_GET['oid'];
if (isset($_GET['OrderProdDBId'])) {
    $OrderProdDBId = $_GET['OrderProdDBId'];
} else {
    $OrderProdDBId = '';
}

$tongji1 = home_tongji(1);
$tongji2 = home_tongji(2);
$tongji3 = home_tongji(3);
$index_std = ShopConfig::getConfig();
?>

<!DOCTYPE html>
<html>
<?php include("header.php"); ?>
<style>
    .form-group1 {
        background-color: white;
        width: 100%;
        height: 100%;
    }

    .modal-title_n {
        margin-left: 5%;
        font-size: 20px;
    }

    .modal-ele {
        margin-left: 10%;
        font-size: 15px;
        font-weight: bold;
        line-height: 30px;
        width: 100%;
    }

    .modal-ele-blan {
        left: 800px;
        font-size: 15px;
        font-weight: bold;
        line-height: 40px;
        position: absolute;
    }

    .modal-ele1 {
        margin-left: 400px;
        font-size: 15px;
        font-weight: bold;
        line-height: 40px;
    }

    .modal-elet {
        margin-left: 900px;
        font-size: 15px;
        color: blue;
    }

    .modal-xiao {
        font-size: 18px;
        background-color: whitesmoke;
    }

    .btn-item {
        height: 50px;
        background: #FF6F20 url(style/images/btn-totop.png) 18px 18px no-repeat;
        background-size: 15px;
        bottom: 700px;
        position: fixed;
        width: 100%;
    }

    .btn-item a {
        height: 50px;
        line-height: 50px;
        display: block;
        border-left: 1px solid #FFF;
        text-align: center;
        font-size: 16px;
        color: #FFF;
        margin: 0 0 0 50px;
        font-weight: bold;
    }

    .btn_a {
        font-size: 18px;
    }

    .modal-f {
        padding: 15px;
        border-top: 1px solid #e5e5e5;
        margin-left: 8%;
    }

    .nex {
        background-color: blueviolet;
        color: white;
        width: 40%;
    }

    .grens {
        color: green;
    }

    .modal-tips {
        font-size: 10px;
    }

    .divs {
        width: 100%;
        height: 100%;
    }

    .divx {
        width: 100%;
        height: 100%;
    }
</style>
<body>
<div class="form-group1" id="order_span">
    <div class="modal-header">
        <h4 class="modal-title_n">只要三步 -- <span style="color: blue;">3</span> / 3</h4>
    </div>

    <div class="divs">
        <div class="modal-ele">
            <p>性別</p>

            <p><span><input type="radio" checked value="1" id="dt1" name="shdt"/><span>無</span></span>

                <span><input type="radio" value="2" id="dt2" name="shdt"/><span>先生</span></span>

                <span><input type="radio" value="3" id="dt3" name="shdt"/><span>小姐</span></span></p>
        </div>
        <div class="modal-ele">
            <p><span class="grens">[二選一]</span>Email信箱</p>

            <p><input type="text" size="35" name="email" id="email" placeholder="信箱必填"/></p>

            <p><span class="modal-tips">下訂成功後，我會寄訂單明細給你唷^^</p>
        </div>
        <div class="modal-ele">
            <p><span class="grens">[二選一]</span>line號碼</p>

            <p><input type="text" size="35" name="line" id="line" placeholder="line號碼必填"/></p>

            <p><span class="modal-tips">下訂成功後，我會聯繫你哦^^</p>
        </div>
        <div class="modal-ele">
            <p>備註</p>

            <p><textarea cols="35" rows="4" placeholder="有什麼特殊需求可以寫這裡哦" id="note" name="note"></textarea></p>
        </div>


        <div class="modal-f">
        <span class="btn_a"> <input type="button" class="nex" value="上一步" onclick="pre_stp2()"/>&nbsp;&nbsp;&nbsp;&nbsp;<input
                class="nex" type="button" value="完成訂單" onclick="finish()"/></span>
        </div>
    </div>
</div>
<div style="display:none;">
    <?php echo str_replace("&nbsp;", ' ', htmlspecialchars_decode($tongji1['tongji'], ENT_QUOTES)) . '<br/>' . str_replace("&nbsp;", ' ', htmlspecialchars_decode($tongji2['tongji'], ENT_QUOTES)) . '<br/>' . str_replace("&nbsp;", ' ', htmlspecialchars_decode($tongji3['tongji'], ENT_QUOTES)) . '<br/>'; ?>
</div>

<script type="text/javascript">
    function pre_stp2() {
        window.location.href = '<?php echo SERVER_ROOT?>' + 'invoicing_stp2.php';
    }


    function finish() {
        //提交通過了就直接可以跳轉到下一步
        var email = $("#email").val();
        var line = $("#line").val();
        var note = $("#note").val();
        var gender = '';
        $("input[name=shdt]").each(function () {
            if ($(this).attr("checked")) {
                gender = $(this).val();
            }
        });

        //数据库id
        $.ajax({
            url: 'order.php',// 跳转到 action
            data: {
                isUpdate: '0_finish',
                oid: '<?php echo $db_oid?>',
                email: email,
                line: line,
                note: note,
                gender: gender,
                OrderProdDBId: '<?php echo $_GET['OrderProdDBId']?>'
            },
            type: 'post',
            cache: false,
            dataType: 'json',
            success: function (data) {
                if (data.msg == "true") {
                    if (data.fk_code == '112') {//在綫支付
                        window.location.href = '<?php echo SERVER_ROOT?>' + 'payment.php?order_sn=' + data.order_sn + '&OrderProdDBId=' + '<?php echo $OrderProdDBId?>'+'&oid='+<?php echo $db_oid?>;
                    } else {
                        window.location.href = '<?php echo SERVER_ROOT?>' + 'finish.php?order_sn=' + data.order_sn + '&OrderProdDBId=' + '<?php echo $OrderProdDBId?>';
                    }
                } else {
                    alert(data.content);
                }
            },
            error: function () {
                alert("服務器錯誤！");
            }
        });
    }


    $(document).ready(function () {
        $("input[name=shdt]").each(function () {
            $(this).click(function () {
                var discount = $(this).attr("checked");
                if (discount == undefined) {
                    $(this).attr("checked", "checked");
                }
            });
        });
    });


</script>
</body>
</html>




